﻿@model ShoppingCartModel
@using Nop.Core.Domain.Orders;
@using Nop.Web.Models.ShoppingCart;

<div class="order-summary-content">
    @Html.Widget("mobile_order_summary_content_before")
    @Html.Partial("_OrderReviewData", Model.OrderReviewData)
    @*@if (Model.AllItems.Count > 0)*@
    @if (Model.Stores.Count > 0)
    {
        if (Model.Warnings.Count > 0)
        {
        <div class="message-error">
            <ul>
                @for (int i = 0; i < Model.Warnings.Count; i++)
                {
                    <li>@Model.Warnings[i]</li>
                }
            </ul>
        </div>
        }
     
@*set "data-ajax" attribute to "false"*@
@*we add enctype = "multipart/form-data" because "File upload" attribute control type requries it*@
        using (Html.BeginRouteForm("ShoppingCart", FormMethod.Post,
        new Dictionary<string, Object> { { "data-ajax", "false" }, { "enctype", "multipart/form-data" } }))
        {
            <div data-role="collapsible-set">
            <div class="cart-store">
                @foreach (var store in Model.Stores)
                {
                    <div data-role="collapsible" data-collapsed="false"><!-- Each Store ???-->
                    @*<div data-role="collapsible-set" data-theme="c" data-content-theme="d">*@
                    @*<div data-role="listview" data-theme="d" data-autodividers="true">*@
                    @*<ul data-role="listview" data-inset="true" data-filter="false">*@
                      <div class="cart-store-header">
                          <div class="cart-store-image">
                            <a href="@Url.RouteUrl("Store", new { storeId = store.Id, SeName = store.SeName })" title="@store.Name">
                                <img alt="@store.Picture.AlternateText" src="@store.Picture.ImageUrl" title="@store.Picture.Title" /></a>
                          </div>
                            <div class="cart-store-name">
                                <a href="@Url.RouteUrl("Store", new { storeId = store.Id, SeName = store.SeName })" title="@store.Name">@store.Name</a>
                            </div>
                            @if (store.Items.Count > 0)
                            {
                                List<int> idList = new List<int>();

                                foreach (var item in store.Items)
                                {
                                    idList.Add(item.Id);
                                }

                                string idString = string.Join("_", idList.ToArray());
                            
                                if (store.Items.Count > 1)
                                {
                                    <div class="cart-store-itemcount">@store.Items.Count Items</div>
                                }
                                else if (store.Items.Count == 1)
                                {
                                    <div class="cart-store-itemcount">1 Item</div>
                                }
                            }

                            @if (!String.IsNullOrEmpty(store.StoreTotal.OrderTotal))
                            {
                                <div class="cart-store-price price">@store.StoreTotal.OrderTotal</div>
                            }
                            else
                            {
                                <div class="cart-store-price">@T("ShoppingCart.Totals.CalculatedDuringCheckout")</div>
                            }
                      </div><!-- / "cart-store-header" -->

                      @if (Model.ShowCheckoutButton)
                      {
                          <div class="cart-store-checkout">
                               <input type="submit" data-theme="e" id="checkoutstore-@store.Id" name="checkoutstore-@store.Id" value="@T("Checkout.Button")" data-shadow="false" data-corners="false"/>
                          </div>
                      }                     
                      @* Remove *@
                      <div class="remove-store">
                          <a href="@Url.RouteUrl(("RemoveProductFromCart"))" data-role="button" data-theme="d" data-shadow="false" data-corners="false">@T("Common.Remove")</a>
                      </div>

                        <div class="cart">
                        <ul data-role="listview" data-inset="true" data-filter="false">
                            @foreach (var item in store.Items)
                            {
                                <li>
                                    <div class="cart-item-row">
                                        <div class="product">
                                            <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="View details">
                                                <img src="@item.Picture.ImageUrl" alt="@item.Picture.AlternateText" title="@item.Picture.Title" />
                                                <br />@item.ProductName</a>

                                                @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                                {
                                                    <div class="attributes">
                                                        @Html.Raw(item.AttributeInfo)
                                                    </div>
                                                }
                                                @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                                {
                                                    <div class="recurring-info">
                                                        @Html.Raw(item.RecurringInfo)
                                                    </div>
                                                }
                                                @if (item.Warnings.Count > 0)
                                                {
                                                    <div class="message-error">
                                                        <ul>
                                                            @for (int i = 0; i < item.Warnings.Count; i++)
                                                            {
                                                                <li>@item.Warnings[i]</li>
                                                            }
                                                        </ul>
                                                    </div>
                                                }
                                        </div>
                                        @if (Model.ShowSku && !String.IsNullOrEmpty(item.Sku))
                                        {
                                            <div class="sku">
                                                @T("ShoppingCart.SKU"): @item.Sku
                                            </div>
                                        }
                            
                                        <div class="unitprice"> <!--* Price *-->
                                            @T("ShoppingCart.UnitPrice"): @item.UnitPrice
                                        </div>
                                        <!-- Qty -->
                                        <div data-role="fieldcontain" class="quantity">
                                                    <label>@T("ShoppingCart.Quantity"):</label> 
                                                    @if (Model.IsEditable)
                                                    {
                                                        if (item.AllowedQuantities.Count > 0)
                                                        {
                                                        <select name="itemquantity@(item.Id)" class="qty-dropdown"  data-mini="true" data-inline="true">
                                                            @foreach (var qty in item.AllowedQuantities)
                                                            {
                                                                <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                                            }
                                                        </select>
                                                        }
                                                        else
                                                        {
                                                        <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="qty-input" />
                                                        }
                                                    }
                                                    else
                                                    {
                                                        <span>@item.Quantity</span>
                                                    }
                                        </div>

                                        <div class="totalprice"> <!-- Total Price -->
                                            @T("ShoppingCart.ItemTotal"): @item.SubTotal
                                            @if (!String.IsNullOrEmpty(item.Discount))
                                            {
                                                <div class="discount">
                                                    @T("ShoppingCart.ItemYouSave"): @item.Discount
                                                </div>
                                            }
                                        </div>
                                        @if (Model.IsEditable)
                                        {
                                            <div class="ui-grid-a">
                                               <div class="ui-block-a"><!--class="remove"-->
                                                    <input type="submit" name="removefromcart-@(item.Id)" value="@T("ShoppingCart.Remove")" />
                                                </div>                                     
                                                <div class="ui-block-b"><!-- class="updateitem"-->
                                                    <input type="submit" name="updatecartitem-@(item.Id)" value="@T("ShoppingCart.UpdateCartItem")" />
                                                </div>
                                           </div>
                                         }
                                        </div>
                                  </li>
                                }
                         </ul>
                    </div><!-- End "cart"-->
                   @*<hr />*@
                 </div><!-- End data-role="collapsible"-->
                }
            </div><!-- / Cart-store -->  
            </div><!-- / data-role="collapsible-set" -->
        }
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }
    @Html.Widget("order_summary_content_after")

    <script type="text/javascript">
    </script>

    <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" />
</div>


                @*******************************************************************************@
                @*
                @foreach (var item in Model.AllItems)
                {
                    <li>
                        <div class="cart-item-row">
                            <div class="product">
                                <a href="@Url.RouteUrl("Product", new { SeName = item.ProductSeName })" title="View details">
                                    <img src="@item.Picture.ImageUrl" alt="@item.Picture.AlternateText" title="@item.Picture.Title" />
                                    <br />@item.ProductName</a>

                                @if (!String.IsNullOrEmpty(item.AttributeInfo))
                                {
                                    <div class="attributes">
                                        @Html.Raw(item.AttributeInfo)
                                    </div>
                                }
                                @if (!String.IsNullOrEmpty(item.RecurringInfo))
                                {
                                    <div class="recurring-info">
                                        @Html.Raw(item.RecurringInfo)
                                    </div>
                                }
                                @if (item.Warnings.Count > 0)
                                {
                                    <div class="message-error">
                                        <ul>
                                            @for (int i = 0; i < item.Warnings.Count; i++)
                                            {
                                                <li>@item.Warnings[i]</li>
                                            }
                                        </ul>
                                    </div>
                                }
                            </div>
                            @if (Model.ShowSku && !String.IsNullOrEmpty(item.Sku))
                            {
                                <div class="sku">
                                    @T("ShoppingCart.SKU"): @item.Sku
                                </div>
                            }
                            
                            <div class="unitprice"> <!--* Price *-->
                                @T("ShoppingCart.UnitPrice"): @item.UnitPrice
                            </div>
                            
                            <!-- Qty -->
                            <div data-role="fieldcontain" class="quantity">
                                    <!--<fieldset data-role="controlgroup">-->
                                        <label>@T("ShoppingCart.Quantity"):</label> 
                                        @if (Model.IsEditable)
                                        {
                                            if (item.AllowedQuantities.Count > 0)
                                            {
                                            <select name="itemquantity@(item.Id)" class="qty-dropdown"  data-mini="true" data-inline="true">
                                                @foreach (var qty in item.AllowedQuantities)
                                                {
                                                    <option selected="@qty.Selected" value="@qty.Value">@qty.Value</option>
                                                }
                                            </select>
                                            }
                                            else
                                            {
                                            <input name="itemquantity@(item.Id)" type="text" value="@(item.Quantity)" class="qty-input" />
                                            }
                                        }
                                        else
                                        {
                                            <span>@item.Quantity</span>
                                        }
                                    <!--</fieldset>-->
                            </div>

                            <div class="totalprice"> <!-- Total Price -->
                                @T("ShoppingCart.ItemTotal"): @item.SubTotal
                                @if (!String.IsNullOrEmpty(item.Discount))
                                {
                                    <div class="discount">
                                        @T("ShoppingCart.ItemYouSave"): @item.Discount
                                    </div>
                                }
                            </div>
                            @if (Model.IsEditable)
                            {
                                <div class="ui-grid-a">
                                   <div class="ui-block-a"><!--class="remove"-->
                                        <input type="submit" name="removefromcart-@(item.Id)" value="@T("ShoppingCart.Remove")" />
                                    </div>                                     
                                    <div class="ui-block-b"><!-- class="updateitem"-->
                                        <input type="submit" name="updatecartitem-@(item.Id)" value="@T("ShoppingCart.UpdateCartItem")" />
                                    </div>
                               </div>
                            }
                        </div>
                    </li>
                }*@

                 @*******************************************************************************@

          @*  if (!String.IsNullOrEmpty(Model.CheckoutAttributeInfo))
            {
        <div class="selected-checkout-attributes">
            @Html.Raw(Model.CheckoutAttributeInfo)
        </div>
            }
        <div>
            @if (Model.IsEditable)
            {
                <div class="common-buttons">
                    <input type="submit" name="continueshopping" value="@T("ShoppingCart.ContinueShopping")" />
                    <div style="display: none;">
                        <input type="submit" name="startcheckout" value="startcheckout" id="startcheckout" />
                    </div>
                </div>
                @Html.Partial("_CheckoutAttributes", Model.CheckoutAttributes, new ViewDataDictionary())
            }
        </div> *@
                    
        @*
        <div class="cart-footer">
            @if (Model.IsEditable)
            {
                if (!String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                {
                <div>
                    <div class="min-amount-warning">
                        @Model.MinOrderSubtotalWarning
                    </div>
                </div>
                }
            }
            <div class="cart-collaterals">
                @if (Model.IsEditable)
                {
                    <div class="deals">
                        @Html.Partial("_DiscountBox", Model.DiscountBox)
                        @Html.Partial("_GiftCardBox", Model.GiftCardBox)
                        @Html.Widget("mobile_order_summary_content_deals")
                    </div>
                }
            </div>
            <div class="totals">
                @Html.Action("OrderTotals", "ShoppingCart", new { isEditable = Model.IsEditable })
                @if (Model.IsEditable)
                {
                    if (Model.TermsOfServiceEnabled)
                    {
                    <div class="terms-of-service">
                        <input id="termsofservice" type="checkbox" name="termsofservice" />
                        <label for="termsofservice">@T("Checkout.TermsOfService.IAccept")</label>
                    </div>
                    }
                    <div class="checkout-buttons">
                        @if (String.IsNullOrEmpty(Model.MinOrderSubtotalWarning))
                        {
                            <script type="text/javascript">
                                $(document).ready(function () {
                                    $('#checkout').click(function () {
                                        //terms of services
                                        var termOfServiceOk = true;
                                        @if (Model.TermsOfServiceEnabled)
                                        {
                                                <text>
                                        if (!$('#termsofservice').is(':checked')) {
                                            alert('@T("Checkout.TermsOfService.PleaseAccept")');
                                            termOfServiceOk = false;
                                        }
                                        else {
                                            termOfServiceOk = true;
                                        }
                                                </text>
                                        }
                                        if (termOfServiceOk) {
                                            $('#startcheckout').trigger("click");
                                        }
                                    });
                                });
                            </script>
                            <input type="submit" name="checkout" data-theme="e" value="@T("Checkout.Button")" id="checkout" onclick="javascript: startcheckout()" />
                        }
                    </div>
                }
            </div>
        </div>
        }
        if (Model.IsEditable)
        {
        <div class="addon-buttons">
            <!--Payment method buttons (e.g. GoogleCheckoutButton, Paypal Express)-->
            @Html.Partial("_ButtonPaymentMethod", Model)
        </div>
        }
    }
    else
    {
        @T("ShoppingCart.CartIsEmpty")
    }
    @Html.Widget("mobile_order_summary_content_after")
    
</div>*@
